package com.xakcop.p4reviewboard;

import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class Activator extends AbstractUIPlugin {

  public static final String PLUGIN_ID = "com.xakcop.p4reviewboard";

  private static Activator plugin;

  public Activator() {
  }

  public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
  }

  public void stop(BundleContext context) throws Exception {
    plugin = null;
    super.stop(context);
  }

  public static Activator getDefault() {
    return plugin;
  }

  public static void logError(String msg, Throwable t) {
    plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, msg, t));
  }

  public static void trace(String msg) {
    if (plugin.isDebugging()) {
      System.out.println("[p4reviewboard] " + msg);
    }
  }

  /**
   * Returns an image descriptor for the image file at the given plug-in
   * relative path
   * 
   * @param path
   *          the path
   * @return the image descriptor
   */
  public static ImageDescriptor getImageDescriptor(String path) {
    return imageDescriptorFromPlugin(PLUGIN_ID, path);
  }
}
